home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 May: Tool Chest / Dev.CD May 97 TC.toast / Sample Code / Snippets / QuickDraw / DeepScreen Picker / DeepScreen Picker.p < prev    next >
Encoding:
Text File  |  1992-07-15  |  4.4 KB  |  157 lines  |  [TEXT/MPS ]

  1. {------------------------------------------------------------------------------
  2. #
  3. #    Macintosh Developer Technical Support
  4. #
  5. #    DeepScreen Picker Sample Application
  6. #
  7. #    DeepScreen Picker   -   Make file name.
  8. #    DeepScreen Picker.p    -    MPW 3.2 Pascal Source
  9. #    DeepScreen Picker.r    -    MPW 3.2 Rez Source
  10. #
  11. #    Purpose:
  12. #
  13. #    This is a very simple sample program that demonstrates how to force the 
  14. #    Color Picker dialog onto the deepest device available.  It does nothing
  15. #    more than save the current GDevice, find the deepest GDevice, make it
  16. #    current and activate (and center) the Color Picker dialog.  It's not a
  17. #    *real* app by a long shot.
  18. #
  19. #    Dave Hersey, MacDTS, 3/21/91
  20. #
  21. ------------------------------------------------------------------------------}
  22.  
  23. Program DeepScreen;
  24.  
  25. USES    QuickDraw, ToolIntf, Picker, Packages;
  26.  
  27. CONST
  28.  
  29.     cpDLOG    = -5760;    (* The resource number of the Color Picker Dialog. *)
  30.     
  31.     
  32. { Initialize everything for the program, make sure we can run. }
  33.  
  34. Procedure Initialize;
  35.  
  36. VAR
  37.     err            : OSErr;
  38.     theWorld    : SysEnvRec;
  39.     
  40. BEGIN
  41.  
  42. {    Test the computer to be sure we can do color.  If not we would crash,
  43.     which would be bad.  If we can’t run, just beep and exit. }
  44.  
  45.     err := SysEnvirons(1, theWorld);
  46.  
  47.     IF NOT (theWorld.hasColorQD) THEN
  48.     BEGIN
  49.         SysBeep(3);
  50.         ExitToShell;
  51.     END;
  52.     
  53. {    Initialize all the needed managers. }
  54.  
  55.     InitGraf(@thePort);
  56.     InitFonts;
  57.     InitWindows;
  58.     InitMenus;
  59.     TEInit;
  60.     InitDialogs(NIL);
  61.     InitCursor;
  62.  
  63. END;    { Initialize }
  64.  
  65.  
  66.  
  67. {    Display the Color Picker dialog on the deepest device.  Note that this
  68.     procedure does not distinguish between color and grayscale devices, it
  69.     only returns the deepest device it finds.  If that makes a difference,
  70.     or if the color device should win if we have a tie for deepest GDevice,
  71.     you will need to alter the code.  In this case, you should call
  72.     GetDeviceList then look at each device in the list rather than call
  73.     GetMaxDevice.  You can check for color capability by looking at the
  74.     gdDevType bit of gdFlags with TestDeviceAttribute.  If this bit is set,
  75.     color is supported.  You can use that and the pixelSize of the GDevice's
  76.     gdPMap to make your own GDevice selection.}
  77.  
  78. Procedure DeepPick;
  79.  
  80. VAR
  81.     deepGDH                    : GDHandle;
  82.     inColor, outColor        : RGBColor;
  83.     where                    : Point;
  84.     cpWidth, cpHeight        : Integer;
  85.     scWidth, scHeight        : Integer;
  86.     deepRect                : Rect;
  87.     cPickDLOG                : DialogTHndl;
  88.     bounds                    : Rect;
  89.     
  90. BEGIN
  91.  
  92. {    Find the bounds of the deepest device.  Passing the maximum enclosing
  93.     rectangle to GetMaxDevice assures that we find the deepest device
  94.     available. }
  95.  
  96.     SetRect(bounds, -32767, -32767, 32767, 32767);
  97.     deepGDH := GetMaxDevice(bounds);
  98.     deepRect := deepGDH^^.gdRect;
  99.  
  100.  
  101. {    If the device we found is the main GDevice, its top-left corner will be at
  102.     (0, 0).  Passing this value to GetColor will neatly place the Color Picker
  103.     dialog on the screen.  If the top-left corner is not (0, 0), the deepest
  104.     screen is not the main GDevice.  In this case, we'll have to calculate the
  105.     dialog's position ourselves. }
  106.  
  107.     IF (deepGDH <> GetMainDevice) THEN
  108.     BEGIN
  109.  
  110. {    Not the main GDevice.  Load the Color Picker dialog's resource so we can
  111.     get its dimensions.  Do the calculations necessary to center the dialog
  112.     horizontally and align it so that 1/3 of the remaining vertical whitespace
  113.     is above the dialog.  This will position the dialog the way the Color
  114.     Picker would have if this were the main GDevice and we set 'where' to
  115.     (0, 0).  When done, release the resource. }
  116.  
  117.         cPickDLOG := DialogTHndl (GetResource('DLOG', cpDLOG));
  118.  
  119.         IF (cPickDLOG <> nil) THEN
  120.         BEGIN
  121.             cpWidth := cPickDLOG^^.boundsRect.right - cPickDLOG^^.boundsRect.left;
  122.             cpHeight := cPickDLOG^^.boundsRect.bottom - cPickDLOG^^.boundsRect.top;
  123.             scWidth := deepRect.right - deepRect.left;
  124.             scHeight := deepRect.bottom - deepRect.top;
  125.             deepRect.left := deepRect.left + (scWidth - cpWidth) DIV 2;
  126.             deepRect.top := deepRect.top + (scHeight - cpHeight) DIV 3;
  127.             ReleaseResource(Handle(cPickDLOG));
  128.         END;
  129.     END;
  130.  
  131.  
  132. {    Set 'where' to the appropriate value to neatly place the dialog.  For our
  133.     initial color selection, I've picked fushia.  When all set, call GetColor. }
  134.  
  135.     SetPt(where, deepRect.left, deepRect.top);
  136.     
  137.     inColor.red := 65535;
  138.     inColor.green := 0;
  139.     inColor.blue := 65535;
  140.  
  141.     IF GetColor(where, 'Pick a color, any color:', inColor, outColor) THEN
  142.       (* whatever. *);
  143.  
  144. END;    { DeepPick }
  145.  
  146.  
  147.  
  148. {    Main body of program DeepScreen.  Initialize, then display the Color Picker dialog
  149.     on the deepest device. }
  150.  
  151. BEGIN 
  152.  
  153.     Initialize;
  154.     DeepPick;
  155.  
  156. END.    { DeepScreen Picker }
  157.